import request from '@/utils/request'
import type { ApiResult, BaseIds, Kv, PageSchema } from '@/api/api'
import type {
  M2rDTO,
  Role,
  RoleAddDTO,
  RoleModDTO,
  RoleQueryDTO,
} from '@/api/acl/role/type'

const BASE_URL = '/admin/api/v1/acl/role'
const API = {
  BASE_URL,
  PAGE_URL: BASE_URL + '/page',
  LIST_URL: BASE_URL + '/list',
  REMOVE_URL: BASE_URL + '/rm',
  SWITCH_URL: BASE_URL + '/switch',
  MENUS_URL: BASE_URL + '/menus',
  M2R_URL: BASE_URL + '/m2r',
  TENANT_ONLY_URL: BASE_URL + '/tenant/only',
  ROLE_SCOPE_URL: BASE_URL + '/scope/enums',
}
// 添加角色信息表
export const roleAdd = (data: RoleAddDTO) => {
  return request.post<any, ApiResult<unknown>>(API.BASE_URL, data)
}
// 修改角色信息表
export const roleMod = (data: RoleModDTO) => {
  return request.put<any, ApiResult<unknown>>(API.BASE_URL, data)
}
// 删除角色信息表
export const roleDel = (data: BaseIds) => {
  return request.post<any, ApiResult<unknown>>(API.REMOVE_URL, data)
}
// 查询角色信息表
export const roleList = (data: RoleQueryDTO) => {
  return request.post<any, ApiResult<Role[]>>(API.LIST_URL, data)
}
// 查询分页数据
export const roleQuery = (data: RoleQueryDTO) => {
  return request.post<any, ApiResult<PageSchema<Role>>>(API.PAGE_URL, data)
}
//转换角色性质
export const roleSwitch = (id: string) => {
  return request.put<any, ApiResult<unknown>>(API.SWITCH_URL + `/${id}`)
}

export const roleMenus = (id: string) => {
  return request.get<any, ApiResult<string[]>>(API.MENUS_URL + `/${id}`)
}

export const m2r = (data: M2rDTO) => {
  return request.post<any, ApiResult<unknown>>(API.M2R_URL, data)
}

export const tenantRoles = () => {
  return request.get<any, ApiResult<Role[]>>(API.TENANT_ONLY_URL)
}
export const roleScopes = () => {
  return request.get<any, ApiResult<Kv[]>>(API.ROLE_SCOPE_URL)
}
